package com.atguigu.bigdata.spark.core.rdd.operator.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * create by undeRdoG on  2021-06-13  14:21
  * 凡心所向，素履以往，生如逆旅，一苇以航。
  */
object Spark04_RDD_Operation_Action {

  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setAppName("Operator").setMaster("local[*]")
    val sc = new SparkContext(sparkConf)

    //  TODO 行动算子
    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4), 2)

    val res1: collection.Map[Int, Long] = rdd.countByValue()
    //  Map(4 -> 1, 2 -> 1, 1 -> 1, 3 -> 1)
    println(res1)


    val rdd2: RDD[(String, Int)] = sc.makeRDD(List(("a", 1), ("a", 1), ("a", 1), ("b", 1)))

    val res2: collection.Map[String, Long] = rdd2.countByKey()

    println(res2)
  }
}
